﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Caifu.Clients;
using Itfort.Binder;
using Itfort.Web;

namespace Caifu.WebAdmin.Funds
{
	public partial class AddFund : System.Web.UI.Page
	{
		// 0：添加前，1：添加后，2：出错时
		protected int m_OpState = 0;

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!this.IsPostBack)
			{
				BindUtil.Bind2DropDownList(
					ConstantDefinition.GetFundTypes().ToDictionary(kv => (object)kv.Key, kv => (object)kv.Value)
					, this.f_FundType);

				BindUtil.Bind2DropDownList(
					ConstantDefinition.GetInvestmentTypes().ToDictionary(kv => (object)kv.Key, kv => (object)kv.Value)
					, this.f_InvestmentType);

				BindUtil.Bind2DropDownList(
					ConstantDefinition.GetInvestmentStyles().ToDictionary(kv => (object)kv.Key, kv => (object)kv.Value)
					, this.f_InvestmentStyle);

				BindUtil.Bind2DropDownList(
					ConstantDefinition.GetFundStates().ToDictionary(kv => (object)kv.Key, kv => (object)kv.Value)
					, this.f_FundState);

				var investAdvisors = InvestAdvisorClient.GetAllInvestAdvisors();
				BindUtil.Bind2DropDownList(
					investAdvisors.ToDictionary(p => (object)p.Id, p => (object)p.Name)
					, this.f_InvestAdvisorId);

				var trustees = TrusteeClient.GetTrustees();
				BindUtil.Bind2DropDownList(
					trustees.ToDictionary(p => (object)p.Id, p => (object)p.Name)
					, this.f_TrusteeId);
			}
		}

		protected void BtnOK_Click(object sender, EventArgs e)
		{
			var fundInfo = ConverterFactory.ConvertTo<Fund>(Request.Form, "f_");
			FundClient.AddFund(fundInfo);
			m_OpState = 1;
		}
	}
}